package com.youxue.teachin.update;

import java.io.File;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import com.youxue.teachin.BuildConfig;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-10-30 23:17
 * @version: 9.1.0
 */
public class AutoInstall {
    /**
     * 安装
     *
     * @param context
     *            接收外部传进来的context
     */
    public static void install(Context context, String url) {

        // 核心是下面几句代码
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(Uri.fromFile(new File(url)), "application/vnd.android.package-archive");
        try {
            context.startActivity(intent);
        } catch (Throwable throwable) {
            if (BuildConfig.DEBUG) {
                throwable.printStackTrace();
            }
        }

    }
}
